package com.seek.edustatistics.schedule;

import com.seek.edustatistics.service.StatisticsDailyService;
import com.seek.edustatistics.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author: wml
 * @since: 2022/3/6 14:46
 */
@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    // cron 表达式在 springboot 中写 6 位，默认年份是当前年份，写 7 位会报错
    // "0/5 * * * * ?" 表示每个 5 秒钟执行一次此方法
    /*@Scheduled(cron = "0/5 * * * * ?")
    public void task1() {
        System.out.println("task1 执行了" + System.currentTimeMillis());
    }*/

    // 在每天 00:00:30 点，执行方法。把数据进行查询添加
    @Scheduled(cron = "30 0 0 * * ?")
    public void task2() {
        statisticsDailyService.countRegister(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
    }
}
